let base_url = "http://59.110.91.222:4000"
const $request = function(url, method = "GET", data = {}) {
	// 显示加载动画
	uni.showLoading({
		title: '加载中...',
		mask: true // 添加遮罩层防止用户重复点击
	})
	
	return new Promise((resolve, reject) => {
		uni.request({
			url: base_url + url,
			method,
			data,
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				reject(err)
			},
			complete: () => {
				// 无论成功失败，都隐藏加载动画
				uni.hideLoading()
			}
		})
	})
}

uni.$base_url = base_url

uni.$get = function(url, data = {}) {
	return $request(url, "GET", data)
}

uni.$post = function(url, data = {}) {
	return $request(url, "POST", data)
}

uni.$put = function(url, data = {}) {
	return $request(url, "PUT", data)
}

uni.$delete = function(url, data = {}) {
	return $request(url, "DELETE", data)
}